const http = {
	// baseUrl0: '/h5api/',
	// baseUrl0: 'http://192.168.0.16:7000/',
	// baseUrl0: 'http://app.youjiatong.cn/',
	// baseUrl0: 'http://geen.vaiwan.com/',
	baseUrl0: 'http://47.112.121.220:5050/',
	baseUrl1: 'http://192.168.0.107:8010/user/v1/',
	baseUrl2: 'http://192.168.0.107:8020/learning/v1/',
	
	request: function(url, method, postData) {
		uni.showLoading({
			title: '请稍等'
		})

		return new Promise((resolve, reject) => {
			console.log(http.baseUrl0+url)
			uni.request({
				url: http.baseUrl0+url,
				header: {
					"Content-Type": "application/json; charset=UTF-8"
				},
				method: method,
				data: postData,
				success: (res) => {
					// if(res.data.code == 500){
					// 	setTimeout(function(){
					// 		uni.navigateTo({
					// 			url:'/pages/user/login'
					// 		})
					// 	},1500)
					// }else 
					console.log(res)
					if (res.data.code == 401) {
						setTimeout(function() {
							uni.navigateTo({
								url: '/pages/login/login'
							})
						}, 1500)
					}
					// console.log(res.data.code == 422)
					resolve(res)
					uni.hideLoading()
				},
				fail: (res) => {
					reject(res)
					uni.hideLoading()
					uni.showToast({
						title: '网络不给力，请稍后再试',
						icon: 'none'
					})
				}
			})
		})
	},
}

export default http
